package com.cencat.order.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 订单明细实体类
 * @author cencat
 * @description 固定商家场景多租户SaaS企业综合管理系统订单明细实体
 * @since 2024-01-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_order_item")
@Schema(name = "OrderItem", description = "订单明细实体")
public class OrderItem implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "订单明细ID")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    @Schema(description = "租户ID")
    @TableField("tenant_id")
    @NotNull(message = "租户ID不能为空")
    private Long tenantId;

    @Schema(description = "订单ID")
    @TableField("order_id")
    @NotNull(message = "订单ID不能为空")
    private Long orderId;

    @Schema(description = "订单编号")
    @TableField("order_no")
    @NotBlank(message = "订单编号不能为空")
    @Size(max = 64, message = "订单编号长度不能超过64个字符")
    private String orderNo;

    @Schema(description = "商家ID")
    @TableField("merchant_id")
    @NotNull(message = "商家ID不能为空")
    private Long merchantId;

    @Schema(description = "产品ID")
    @TableField("product_id")
    @NotNull(message = "产品ID不能为空")
    private Long productId;

    @Schema(description = "产品编码")
    @TableField("product_code")
    @NotBlank(message = "产品编码不能为空")
    @Size(max = 64, message = "产品编码长度不能超过64个字符")
    private String productCode;

    @Schema(description = "产品名称")
    @TableField("product_name")
    @NotBlank(message = "产品名称不能为空")
    @Size(max = 200, message = "产品名称长度不能超过200个字符")
    private String productName;

    @Schema(description = "产品规格")
    @TableField("product_spec")
    @Size(max = 500, message = "产品规格长度不能超过500个字符")
    private String productSpec;

    @Schema(description = "产品图片URL")
    @TableField("product_image")
    @Size(max = 500, message = "产品图片URL长度不能超过500个字符")
    private String productImage;

    @Schema(description = "产品单价")
    @TableField("unit_price")
    @NotNull(message = "产品单价不能为空")
    @DecimalMin(value = "0.01", message = "产品单价必须大于0")
    @Digits(integer = 10, fraction = 2, message = "产品单价格式不正确")
    private BigDecimal unitPrice;

    @Schema(description = "购买数量")
    @TableField("quantity")
    @NotNull(message = "购买数量不能为空")
    @Min(value = 1, message = "购买数量必须大于0")
    private Integer quantity;

    @Schema(description = "小计金额")
    @TableField("subtotal_amount")
    @NotNull(message = "小计金额不能为空")
    @DecimalMin(value = "0.01", message = "小计金额必须大于0")
    @Digits(integer = 10, fraction = 2, message = "小计金额格式不正确")
    private BigDecimal subtotalAmount;

    @Schema(description = "优惠金额")
    @TableField("discount_amount")
    @DecimalMin(value = "0.00", message = "优惠金额不能为负数")
    @Digits(integer = 10, fraction = 2, message = "优惠金额格式不正确")
    private BigDecimal discountAmount;

    @Schema(description = "实际金额")
    @TableField("actual_amount")
    @NotNull(message = "实际金额不能为空")
    @DecimalMin(value = "0.01", message = "实际金额必须大于0")
    @Digits(integer = 10, fraction = 2, message = "实际金额格式不正确")
    private BigDecimal actualAmount;

    @Schema(description = "产品分类ID")
    @TableField("category_id")
    private Long categoryId;

    @Schema(description = "产品分类名称")
    @TableField("category_name")
    @Size(max = 100, message = "产品分类名称长度不能超过100个字符")
    private String categoryName;

    @Schema(description = "产品品牌ID")
    @TableField("brand_id")
    private Long brandId;

    @Schema(description = "产品品牌名称")
    @TableField("brand_name")
    @Size(max = 100, message = "产品品牌名称长度不能超过100个字符")
    private String brandName;

    @Schema(description = "产品重量(克)")
    @TableField("weight")
    @DecimalMin(value = "0.00", message = "产品重量不能为负数")
    @Digits(integer = 10, fraction = 2, message = "产品重量格式不正确")
    private BigDecimal weight;

    @Schema(description = "产品体积(立方厘米)")
    @TableField("volume")
    @DecimalMin(value = "0.00", message = "产品体积不能为负数")
    @Digits(integer = 10, fraction = 2, message = "产品体积格式不正确")
    private BigDecimal volume;

    @Schema(description = "退款状态：NO_REFUND-未退款，PARTIAL_REFUND-部分退款，FULL_REFUND-全额退款")
    @TableField("refund_status")
    @Pattern(regexp = "^(NO_REFUND|PARTIAL_REFUND|FULL_REFUND)$", message = "退款状态不正确")
    private String refundStatus;

    @Schema(description = "退款金额")
    @TableField("refund_amount")
    @DecimalMin(value = "0.00", message = "退款金额不能为负数")
    @Digits(integer = 10, fraction = 2, message = "退款金额格式不正确")
    private BigDecimal refundAmount;

    @Schema(description = "退款时间")
    @TableField("refund_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime refundTime;

    @Schema(description = "退款原因")
    @TableField("refund_reason")
    @Size(max = 500, message = "退款原因长度不能超过500个字符")
    private String refundReason;

    @Schema(description = "明细备注")
    @TableField("remark")
    @Size(max = 500, message = "明细备注长度不能超过500个字符")
    private String remark;

    @Schema(description = "是否删除：0-未删除，1-已删除")
    @TableField("is_deleted")
    @TableLogic
    private Integer isDeleted;

    @Schema(description = "创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    @Schema(description = "创建人ID")
    @TableField("create_by")
    private Long createBy;

    @Schema(description = "更新人ID")
    @TableField("update_by")
    private Long updateBy;

    @Schema(description = "版本号")
    @TableField("version")
    @Version
    private Integer version;
}